﻿using ATEGo;
using System;
using System.Windows.Forms;

namespace Degrade
{
    public partial class Input_Barcode : Form
    {
        public Input_Barcode(int threadIndex)
        {
            InitializeComponent();
            this.Text = "线程"+ (threadIndex+1).ToString() + "-请输入整机条码：";
            label1.Text = "线程" + (threadIndex + 1).ToString()+"-请输入整机条码：";
        }

        public Func<string,bool> CheckBarcode { get; set; }

        public Action<string> SuccessAction { get; set; }

        private void button1_Click(object sender, EventArgs e)
        {
            //查询条码的正确性
            string barcode = textBox1.Text.Trim();
            if (CheckBarcode(barcode))
            {
                SuccessAction(barcode);
                this.Close();
            }
            else
            {
                MsgShow.Error($"输入条码错误：{barcode}");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                button1_Click(this, null);
            }
        }
    }
}
